//
//  SecondGViewController.m
//  DaJiHui
//
//  Created by Hao on 2017/6/26.
//  Copyright © 2017年 Hao. All rights reserved.
#import "SecondModel.h"
#import "AFNetworking.h"
#import "SecondTableViewCell.h"
#import "SecondGViewController.h"
#import "MMComBoBox.h"
#import "DOPDropDownMenu.h"
#import "NSArray+CZSafeAccess.h"
#import "FirstTwoViewController.h"
@interface SecondGViewController ()<DOPDropDownMenuDataSource,DOPDropDownMenuDelegate,UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSArray *mutableArray;
@property (nonatomic, weak) DOPDropDownMenu *menu;
@property (nonatomic, strong) MMComBoBoxView *comBoBoxView;
@property (nonatomic, strong) NSArray *hostels;
@property (nonatomic, strong) NSArray *areas;
@property (nonatomic, strong) NSArray *sorts;
@property (nonatomic, strong) NSArray *four;

@property (nonatomic, strong) NSString *strY;
@property (nonatomic, strong) NSString *strf;
@property (nonatomic, strong) NSString *strA;

@property (nonatomic, strong) NSArray *hostelsq;
@property (nonatomic, strong) NSArray *areasq;
@property (nonatomic, strong) NSArray *sortsq;
@property (nonatomic, strong) NSArray *fourq;

@property (nonatomic, strong) NSString *xl;
@property (nonatomic, strong) NSString *pj;
@property (nonatomic, strong) NSString *time;

@property (nonatomic, strong) NSMutableArray *hostelsid;
@property (nonatomic, strong) NSMutableArray *areasid;
@property (nonatomic, strong) NSMutableArray *sortsid;
@property (nonatomic, strong) NSMutableArray *fourid;

@property (nonatomic, strong) NSMutableArray *gongSiArr;
@property (nonatomic, strong) NSMutableArray *hostelsawe;
@property (nonatomic, strong) NSMutableArray *areasawe;
@property (nonatomic, strong) NSMutableArray *fourawe;
@property (nonatomic, strong) NSMutableArray *sortsawe;
@property (nonatomic, strong) UITableView *myTableView;
@end

@implementation SecondGViewController
{
    NSArray*TypeArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
     [self gada];
    [self makeBaseUI];
    
    [self makeBaseUI2];
    
   
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.title = @"明星企业";
    
    // Do any additional setup after loading the view.
}
-(void)gada{
    _xl=[[NSString alloc]init];
    _pj =[[NSString alloc]init];
    _time =[[NSString alloc]init];
    
    _hostels = [[NSArray alloc]init];
     _areas = [[NSArray alloc]init];
     _sorts = [[NSArray alloc]init];
     _four = [[NSArray alloc]init];
    
    _hostelsid = [[NSMutableArray alloc]init];
    _areasid= [[NSMutableArray alloc]init];
    _sortsid = [[NSMutableArray alloc]init];
    _fourid = [[NSMutableArray alloc]init];
   
    _hostelsawe = [[NSMutableArray alloc]init];
    _sortsawe = [[NSMutableArray alloc]init];
    _areasawe = [[NSMutableArray alloc]init];
    _fourawe = [[NSMutableArray alloc]init];
    
    self.gongSiArr = [[NSMutableArray alloc]init];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer.timeoutInterval = 10.f;
    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
    NSURL *url = [NSURL URLWithString:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist"];
    [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"成功%@",responseObject);
        _hostels=responseObject[@"restwo"];
        _areas = responseObject[@"resone"];
        _sorts =responseObject[@"loares"];
        _xl = responseObject[@"xl"];
        _pj = responseObject[@"pj"];
        _time = responseObject[@"time"];
        _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
        for (NSMutableDictionary *dic in _hostels)
        {
            NSLog(@"%@", dic);
            [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
            [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
        
            NSLog(@"hostelsa ==%@",self.hostelsawe);
             NSLog(@"hostelsaid ==%@",self.hostelsid);
            
        }
        
        [_hostelsawe insertObject:@"行业" atIndex:0];
        
        for (NSMutableDictionary *dic in _areas)
        {
            NSLog(@"%@", dic);
            [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
            
            [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            
            NSLog(@"areasa==%@",self.areasawe);
            
             NSLog(@"areasaid==%@",self.areasid);
            
        }
        [_areasawe insertObject:@"分类" atIndex:0];
        
        
        for (NSMutableDictionary *dic in _sorts)
        {
            NSLog(@"%@", dic);
            [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
             [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            NSLog(@"sortsa==%@",self.sortsawe);
            NSLog(@"sortsaid==%@",self.sortsid);
            
        }
        [_sortsawe insertObject:@"地区" atIndex:0];

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.myTableView reloadData];
            [self.menu reloadData];
        });

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败%@",error);
        
    }];
}
-(void)gata{
    _xl=[[NSString alloc]init];
    _pj =[[NSString alloc]init];
    _time =[[NSString alloc]init];
    
    _hostels = [[NSArray alloc]init];
    _areas = [[NSArray alloc]init];
    _sorts = [[NSArray alloc]init];
    _four = [[NSArray alloc]init];
    
    _hostelsid = [[NSMutableArray alloc]init];
    _areasid= [[NSMutableArray alloc]init];
    _sortsid = [[NSMutableArray alloc]init];
    _fourid = [[NSMutableArray alloc]init];
    
    _hostelsawe = [[NSMutableArray alloc]init];
    _sortsawe = [[NSMutableArray alloc]init];
    _areasawe = [[NSMutableArray alloc]init];
    _fourawe = [[NSMutableArray alloc]init];
    
    self.gongSiArr = [[NSMutableArray alloc]init];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer.timeoutInterval = 10.f;
    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
    NSURL *url = [NSURL URLWithString:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist"];
    [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"成功%@",responseObject);
        _hostels=responseObject[@"restwo"];
        _areas = responseObject[@"resone"];
        _sorts =responseObject[@"loares"];
        _xl = responseObject[@"xl"];
        _pj = responseObject[@"pj"];
        _time = responseObject[@"time"];
        _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
        for (NSMutableDictionary *dic in _hostels)
        {
            NSLog(@"%@", dic);
            [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
            [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            
            NSLog(@"hostelsa ==%@",self.hostelsawe);
            NSLog(@"hostelsaid ==%@",self.hostelsid);
            
        }
        
        [_hostelsawe insertObject:@"行业" atIndex:0];
        
        for (NSMutableDictionary *dic in _areas)
        {
            NSLog(@"%@", dic);
            [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
            
            [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            
            NSLog(@"areasa==%@",self.areasawe);
            
            NSLog(@"areasaid==%@",self.areasid);
            
        }
        [_areasawe insertObject:@"分类" atIndex:0];
        
        
        for (NSMutableDictionary *dic in _sorts)
        {
            NSLog(@"%@", dic);
            [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
            [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            NSLog(@"sortsa==%@",self.sortsawe);
            NSLog(@"sortsaid==%@",self.sortsid);
            
        }
        [_sortsawe insertObject:@"地区" atIndex:0];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.myTableView reloadData];
        });
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败%@",error);
        
    }];
}
     
- (void)makeBaseUI{
//    self.hostels = @[@"经济酒店",@"商务酒店",@"连锁酒店",@"度假酒店",@"公寓酒店",@"雨花区",@"雨花区",@"雨花区",@"雨花区"];
//    self.areas = @[@"全城",@"芙蓉区",@"雨花区",@"天心区",@"开福区",@"岳麓区"];
//    self.sorts = @[@"默认排序",@"离我最近",@"好评优先",@"人气优先",@"最新发布"];
    self.four = @[@"排序",@"销量",@"好评",@"最新"];
    //time = 最新  xl 销量  pj 好评
    
    DOPDropDownMenu *menu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, 0) andHeight:44];
    menu.delegate = self;
    menu.dataSource = self;
    [self.view addSubview:menu];
    _menu = menu;
    //     创建menu 第一次显示 不会调用点击代理，可以用这个手动调用
    //    [menu selectDefalutIndexPath];
    [menu selectIndexPath:[DOPIndexPath indexPathWithCol:0 row:0 item:0]];

}
- (void)makeBaseUI2{
    [self.view addSubview:self.myTableView];
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return  CGFLOAT_MIN;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
   
    return  self.gongSiArr.count+1;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.section == self.gongSiArr.count) {
        return 30;
    }
    return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SecondTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//    for(id temp in cell.contentView.subviews)
//    {
//        [temp removeFromSuperview];
//    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (!cell) {
        cell = [[SecondTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.isFormFirst = YES;
        }
    cell.myModel = [self.gongSiArr cz_objectWithIndex:indexPath.section];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    //cell.textLabel.text =[NSString stringWithFormat:@"222"];
    cell.textLabel.textColor = [UIColor orangeColor];
    
    if (indexPath.section == self.gongSiArr.count){
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell3"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell3"];
            cell.textLabel.textAlignment = NSTextAlignmentLeft;
        }
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.text =[NSString stringWithFormat:@"更多商家>>"];
        cell.textLabel.textColor = [UIColor getColorFromRGBString:@"#060606"];
        return cell;
    }
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    //cell.textLabel.text =[NSString stringWithFormat:@"222"];
    cell.textLabel.textColor = [UIColor orangeColor];
    return cell;


}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==self.gongSiArr.count) {
        NSLog(@"煞笔");
        [self gata];
        [self.myTableView reloadData];
        
    }else{
        FirstTwoViewController *vc =[[FirstTwoViewController alloc]init];
        
        SecondModel *model=(SecondModel *)self.gongSiArr[indexPath.section];
        vc.dic = model.myid;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
    
}

- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu
{
    return 4;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    if (column == 0) {
        return _areasawe.count;
    }else if (column == 1){
        return _hostelsawe.count;
    }else if (column == 2){
        return _sortsawe.count;
    }else if(column==3){
        return _four.count;
    }
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        return [_areasawe cz_objectWithIndex:indexPath.row];
    } else if (indexPath.column == 1){
        return [_hostelsawe cz_objectWithIndex:indexPath.row];
    }else if (indexPath.column == 2){
        return [_sortsawe cz_objectWithIndex:indexPath.row];
    }else {
        return [_four cz_objectWithIndex:indexPath.row];
   }
   
}

// new datasource

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    return nil;
}

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    return nil;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column
{
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        return [TypeArr cz_objectWithIndex:indexPath.row];
    } else if (indexPath.column == 1) {
        return [TypeArr cz_objectWithIndex:indexPath.row];
    } else {
        return [TypeArr cz_objectWithIndex:indexPath.row];
    }
}

- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.item >= 0) {
        NSLog(@"点击了 1%ld - 2%ld - 3%ld 项目",indexPath.column,indexPath.row,indexPath.item);
    }else {
        if (indexPath.column==0) {
            if (indexPath.row==0) {
                _hostels = [[NSArray alloc]init];
                _areas = [[NSArray alloc]init];
                _sorts = [[NSArray alloc]init];
                
                _hostelsid = [[NSMutableArray alloc]init];
                _areasid= [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
              
                
                _hostelsawe = [[NSMutableArray alloc]init];
                _sortsawe = [[NSMutableArray alloc]init];
                _areasawe = [[NSMutableArray alloc]init];
               
                
                self.gongSiArr = [[NSMutableArray alloc]init];
                AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                manager.requestSerializer.timeoutInterval = 10.f;
                manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
                manager.requestSerializer = [AFHTTPRequestSerializer serializer];
                manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]];
                manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
                NSURL *url = [NSURL URLWithString:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist"];
                [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"成功%@",responseObject);
                    _hostels=responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts =responseObject[@"loares"];
                    
                    _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsawe);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsawe insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasawe);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasawe insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsawe);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsawe insertObject:@"地区" atIndex:0];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self.myTableView reloadData];
                        [self.menu reloadData];
                    });
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    NSLog(@"失败%@",error);
                    
                }];

            
            }else{
            NSLog(@"点击了4 %ld - 5%ld 项目",indexPath.column,indexPath.row);
            
            _strY=_areasid[indexPath.row-1];
            _hostelsq = [[NSArray alloc]init];
            _areasq = [[NSArray alloc]init];
            _sortsq = [[NSArray alloc]init];
            
            _hostelsid = [[NSMutableArray alloc]init];
            _areasid= [[NSMutableArray alloc]init];
            _sortsid = [[NSMutableArray alloc]init];

            
            _hostelsawe = [[NSMutableArray alloc]init];
            _sortsawe = [[NSMutableArray alloc]init];
            _areasawe = [[NSMutableArray alloc]init];
  
            
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            manager.requestSerializer.timeoutInterval = 10.f;
            manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
            manager.requestSerializer = [AFHTTPRequestSerializer serializer];
            manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
            NSString *str1 = [NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist/hangye/%@",_strY];
            NSURL *url = [NSURL URLWithString:str1];
            [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSLog(@"成功%@",responseObject);
                _hostels=responseObject[@"restwo"];
                _areas = responseObject[@"resone"];
                _sorts =responseObject[@"loares"];
                
                _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                for (NSMutableDictionary *dic in _hostels)
                {
                    NSLog(@"%@", dic);
                    [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                    [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    
                    NSLog(@"hostelsa ==%@",self.hostelsawe);
                    NSLog(@"hostelsaid ==%@",self.hostelsid);
                    
                }
                
                [_hostelsawe insertObject:@"行业" atIndex:0];
                
                for (NSMutableDictionary *dic in _areas)
                {
                    NSLog(@"%@", dic);
                    [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                    
                    [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    
                    NSLog(@"areasa==%@",self.areasawe);
                    
                    NSLog(@"areasaid==%@",self.areasid);
                    
                }
                [_areasawe insertObject:@"分类" atIndex:0];
                for (NSMutableDictionary *dic in _sorts)
                {
                    NSLog(@"%@", dic);
                    [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                    [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    NSLog(@"sortsa==%@",self.sortsawe);
                    NSLog(@"sortsaid==%@",self.sortsid);
                    
                }
                [_sortsawe insertObject:@"地区" atIndex:0];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.myTableView reloadData];
                });
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSLog(@"失败%@",error);
                
            }];
            
            }
            
        }else if (indexPath.column==1){
            if (indexPath.row == 0) {
                return;
            }else{
            NSLog(@"点击了4 %ld - 5%ld 项目",indexPath.column,indexPath.row);
                
            _strf=_hostelsid[indexPath.row-1];
            _hostelsq = [[NSArray alloc]init];
            _areasq = [[NSArray alloc]init];
            _sortsq = [[NSArray alloc]init];
                
            _hostelsid = [[NSMutableArray alloc]init];
            _areasid= [[NSMutableArray alloc]init];
            _sortsid = [[NSMutableArray alloc]init];
            
            _hostelsawe = [[NSMutableArray alloc]init];
            _sortsawe = [[NSMutableArray alloc]init];
            _areasawe = [[NSMutableArray alloc]init];
            _fourawe = [[NSMutableArray alloc]init];
            
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            manager.requestSerializer.timeoutInterval = 10.f;
            manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
            manager.requestSerializer = [AFHTTPRequestSerializer serializer];
            manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
            NSString *str1 = [NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist/hangye/%@/yingye/%@",_strY,_strf];
            NSURL *url = [NSURL URLWithString:str1];
            [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                _hostels=responseObject[@"restwo"];
                _areas = responseObject[@"resone"];
                _sorts =responseObject[@"loares"];
                _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                
                for (NSMutableDictionary *dic in _hostels)
                {
                    NSLog(@"%@", dic);
                    [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                    [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    

                    
                }
                
                [_hostelsawe insertObject:@"行业" atIndex:0];
                
                for (NSMutableDictionary *dic in _areas)
                {
                    NSLog(@"%@", dic);
                    [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                    
                    [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    
                }
                [_areasawe insertObject:@"分类" atIndex:0];
                for (NSMutableDictionary *dic in _sorts)
                {
                    NSLog(@"%@", dic);
                    [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                    [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    
                }
                [_sortsawe insertObject:@"地区" atIndex:0];
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.myTableView reloadData];
                });
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSLog(@"失败%@",error);
                
            }];
                
            }
        }else if (indexPath.column==2){
            if (indexPath.row==0) {
                return;
            }else{
        
            NSLog(@"点击了4 %ld - 5%ld 项目",indexPath.column,indexPath.row);

            _strA=_sortsid[indexPath.row-1];
            _hostelsq = [[NSArray alloc]init];
            _areasq = [[NSArray alloc]init];
            _sortsq = [[NSArray alloc]init];
            
            _hostelsid = [[NSMutableArray alloc]init];
            _areasid= [[NSMutableArray alloc]init];
            _sortsid = [[NSMutableArray alloc]init];
            
            _hostelsawe = [[NSMutableArray alloc]init];
            _sortsawe = [[NSMutableArray alloc]init];
            _areasawe = [[NSMutableArray alloc]init];
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            manager.requestSerializer.timeoutInterval = 10.f;
            manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
            manager.requestSerializer = [AFHTTPRequestSerializer serializer];
            manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
            NSString *str1 = [NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist/hangye/%@/yingye/%@locationa/%@",_strY,_strf,_strA];
            NSURL *url = [NSURL URLWithString:str1];
            [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSLog(@"成功%@",responseObject);
                _hostels=responseObject[@"restwo"];
                _areas = responseObject[@"resone"];
                _sorts =responseObject[@"loares"];
                
                _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                for (NSMutableDictionary *dic in _hostels)
                {
                    NSLog(@"%@", dic);
                    [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                    [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    
                    NSLog(@"hostelsa ==%@",self.hostelsawe);
                    NSLog(@"hostelsaid ==%@",self.hostelsid);
                    
                }
                
                [_hostelsawe insertObject:@"行业" atIndex:0];
                
                for (NSMutableDictionary *dic in _areas)
                {
                    NSLog(@"%@", dic);
                    [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                    
                    [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    
                    NSLog(@"areasa==%@",self.areasawe);
                    
                    NSLog(@"areasaid==%@",self.areasid);
                    
                }
                [_areasawe insertObject:@"分类" atIndex:0];
                for (NSMutableDictionary *dic in _sorts)
                {
                    NSLog(@"%@", dic);
                    [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                    [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                    NSLog(@"sortsa==%@",self.sortsawe);
                    NSLog(@"sortsaid==%@",self.sortsid);
                    
                }
                
                [_sortsawe insertObject:@"地区" atIndex:0];
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.myTableView reloadData];
                });
                
                
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSLog(@"失败%@",error);
                
            }];
        
        
            }
        }else if (indexPath.column ==3){
            if (indexPath.row == 0) {
                return;
            }else if (indexPath.row==1){
                _hostels = [[NSArray alloc]init];
                _areas = [[NSArray alloc]init];
                _sorts = [[NSArray alloc]init];
                
                _hostelsid = [[NSMutableArray alloc]init];
                _areasid= [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _hostelsawe = [[NSMutableArray alloc]init];
                _sortsawe = [[NSMutableArray alloc]init];
                _areasawe = [[NSMutableArray alloc]init];
                
                AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                manager.requestSerializer.timeoutInterval = 10.f;
                manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
                manager.requestSerializer = [AFHTTPRequestSerializer serializer];
                manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]];
                manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
                NSString*str=[NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist/xl/%@",_xl];
                NSURL *url = [NSURL URLWithString:str];
                [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"成功%@",responseObject);
                    _hostels=responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts =responseObject[@"loares"];
                    _xl = responseObject[@"xl"];
                    _pj = responseObject[@"pj"];
                    _time = responseObject[@"time"];
                    _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsawe);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsawe insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasawe);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasawe insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsawe);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsawe insertObject:@"地区" atIndex:0];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self.myTableView reloadData];
                        
                    });
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    NSLog(@"失败%@",error);
                    
                }];

            
            }else if (indexPath.row==2){
                _hostels = [[NSArray alloc]init];
                _areas = [[NSArray alloc]init];
                _sorts = [[NSArray alloc]init];
                
                _hostelsid = [[NSMutableArray alloc]init];
                _areasid= [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];

                _hostelsawe = [[NSMutableArray alloc]init];
                _sortsawe = [[NSMutableArray alloc]init];
                _areasawe = [[NSMutableArray alloc]init];
                
                AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                manager.requestSerializer.timeoutInterval = 10.f;
                manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
                manager.requestSerializer = [AFHTTPRequestSerializer serializer];
                manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]];
                manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
                NSString*str=[NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist/pj/%@",_pj];
                NSURL *url = [NSURL URLWithString:str];
                [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"成功%@",responseObject);
                    _hostels=responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts =responseObject[@"loares"];
                    _xl = responseObject[@"xl"];
                    _pj = responseObject[@"pj"];
                    _time = responseObject[@"time"];
                    _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsawe);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsawe insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasawe);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasawe insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsawe);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsawe insertObject:@"地区" atIndex:0];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self.myTableView reloadData];
                        
                    });
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    NSLog(@"失败%@",error);
                    
                }];
                

                
            }else if (indexPath.row==3){
                _hostels = [[NSArray alloc]init];
                _areas = [[NSArray alloc]init];
                _sorts = [[NSArray alloc]init];
                
                _hostelsid = [[NSMutableArray alloc]init];
                _areasid= [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _hostelsawe = [[NSMutableArray alloc]init];
                _sortsawe = [[NSMutableArray alloc]init];
                _areasawe = [[NSMutableArray alloc]init];
                
                AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                manager.requestSerializer.timeoutInterval = 10.f;
                manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
                manager.requestSerializer = [AFHTTPRequestSerializer serializer];
                manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]];
                manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
                NSString*str=[NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=/Index/storelist/time/%@",_time];
                NSURL *url = [NSURL URLWithString:str];
                [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"成功%@",responseObject);
                    _hostels=responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts =responseObject[@"loares"];
                    _xl = responseObject[@"xl"];
                    _pj = responseObject[@"pj"];
                    _time = responseObject[@"time"];
                    _gongSiArr = [SecondModel transformWithArry:responseObject[@"res"]];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsawe);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsawe insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasawe addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasawe);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasawe insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsawe addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsawe);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsawe insertObject:@"地区" atIndex:0];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self.myTableView reloadData];
                        
                    });
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    NSLog(@"失败%@",error);
                    
                }];
                

            }
        
        }
        
            }
}
- (UITableView *)myTableView{
    
    if (_myTableView == nil) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, ZTY_SCREEN_WIDTH, ZTY_SCREEN_HEIGHT-49-64-44) style:UITableViewStyleGrouped];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.sectionFooterHeight = 0;
        _myTableView.sectionHeaderHeight = 0;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    return _myTableView;
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.myTableView reloadData];
   [self.navigationController setNavigationBarHidden:NO animated:animated];
}
@end
